package com.superzqb.asus.superzqbFragment.superzqbJobShop.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbFragment.superzqbJobShop.Bean.CampusShopAllBean;
import com.superzqb.asus.superzqbUtil.Url;

import java.util.List;


/**
 * Created by asus on 2017/1/21.
 */

public class CampusShopAllAdapter extends BaseAdapter {

    private Context context;
    private List<CampusShopAllBean> list;
    private int select =-1;
    public CampusShopAllAdapter(Context context,List<CampusShopAllBean>list) {
        this.context = context;
        this.list = list;
    }
    public void setList(List<CampusShopAllBean> list) {
        this.list = list;
    }
    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.campus_shop_all_item,parent,false);
            convertView.setTag(new ViewHolder(convertView));
        }
        ViewHolder holder=(ViewHolder) convertView.getTag();
        CampusShopAllBean goods=(CampusShopAllBean)getItem(position);
        holder.gName.setText(goods.getGoodsname());
        holder.uName.setText(goods.getU_id()+"");
        holder.time.setText(goods.getCreatetime());
        holder.price.setText(goods.getPrice());
        holder.hint.setText(goods.getHint()+"");
        Picasso.with(context).load(new Url().getImg_url() +goods.getHead_img()).resize(150,120).into(holder.gImg);
        if(position==select){
            holder.gName.setTextColor(context.getResources().getColor(R.color.colorFont));
        }else{
            holder.gName.setTextColor(context.getResources().getColor(R.color.black));
        }
        return convertView;
    }

    public void changeColor(int position) {
        this.select=position;
    }


     class ViewHolder{
        private ImageView gImg;
        private TextView gName,uName,time,price,hint;
        public ViewHolder(View view){
            gImg=(ImageView)view.findViewById(R.id.goodsimg);
            gName=(TextView)view.findViewById(R.id.gname);
            uName=(TextView)view.findViewById(R.id.username);
            time=(TextView)view.findViewById(R.id.time);
            price=(TextView)view.findViewById(R.id.price);
            hint=(TextView)view.findViewById(R.id.hint);
        }

    }
}
